package com.yx.study.leet.primary.other;

import java.math.BigDecimal;

/**
 * 位1的个数
 * https://leetcode.cn/leetbook/read/top-interview-questions-easy/xn1m0i/
 * */
public class HammingWeight {
    public int hammingWeight(int n) {
        int count = 0;
        while (n != 0) {
            count += n & 1; // 位运算: >>> 无符号右移 >> 有符号右移 n&1 取最右一位
            n = n >>> 1;
        }
        return count;
    }
}
